﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SlimDX.Direct3D10;

namespace System.Windows.Media.Media3D10
{
    /// <summary>
    /// Classe de base pour les <see cref="Model3D10"/> ayant un rendu visuel à l'écran
    /// </summary>
    public abstract class RenderModel3D10 : Model3D10
    {
        #region Data
        private InputLayout _layout = null;
        private VertexBufferBinding[] _vertexBufferBinding;
        #endregion

        #region Protected Properties
        /// <summary>
        /// Obtient le layout de rendu
        /// </summary>
        protected internal InputLayout InputLayout
        {
            get { return _layout; }
        }

        /// <summary>
        /// Obtient le binding de rendu
        /// </summary>
        /// <returns>Retourne le binding de rendu</returns>
        protected internal VertexBufferBinding[] GetVertexBufferBinding()
        {
            return _vertexBufferBinding;
        }
        #endregion

        #region Protected Methods
        /// <summary>
        /// Force la recréation du layout
        /// </summary>
        protected void InvalidateInputLayout()
        {
            _layout = CreateInputLayoutCore();
        }

        /// <summary>
        /// Force la recréation du binding
        /// </summary>
        protected void InvalidateVertexBufferBinding()
        {
            _vertexBufferBinding = CreateVertexBufferBindingCore();
        }

        /// <summary>
        /// Crée le <see cref="InputLayout"/> associé à ce <see cref="RenderModel3D10"/>
        /// </summary>
        /// <returns></returns>
        protected abstract SlimDX.Direct3D10.InputLayout CreateInputLayoutCore();

        /// <summary>
        /// Crée le <see cref="VertexBufferBinding"/> associé à ce <see cref="RenderModel3D10"/>
        /// </summary>
        /// <returns></returns>
        protected abstract SlimDX.Direct3D10.VertexBufferBinding[] CreateVertexBufferBindingCore();
        #endregion

        #region Model3D10 Overrides
        /// <summary>
        /// Appelée lors du changement de l'effet
        /// </summary>
        /// <param name="e"><see cref="DependencyPropertyChangedEventArgs"/> décrivant les informations sur le changement.</param>
        protected override void OnEffectChanged(DependencyPropertyChangedEventArgs e)
        {
            base.OnEffectChanged(e);
            InvalidateInputLayout();
            InvalidateVertexBufferBinding();
        }
        #endregion
    }
}
